﻿/**
 * This is a part of MCServe, which is available under the Apache license 2.0.
 * With this code, you may do whatever you want as long as that is not in conflict with this license.
 * In addition, you should have a reference to the original project to include (http://mcserve.codeplex.com).
 * 
 * Author       : Lars Krämer ( Xe77a )
 * Website      : http://www.lkraemer.de
 * Project      : MCServe (http://mcserve.codeplex.com)
 * Copyright    : Copyright (c) 2013 lkraemer.de
 * License      : http://mcserve.codeplex.com/license
 * Description  : This is a part of the core functionality of the server
 */

using MCServeLib.Types;
using System;
using System.ComponentModel;

namespace MCServeCore.Components
{
    public class Property : INotifyPropertyChanged
    {
        private String _Name = "";
        private Object _Value = "";
        private Guid _Guid = new Guid();
        private PropertyType _Type = PropertyType.OBJECT;

        /**
         * Konstruktor
         */
        public Property()
        {
            Name = "";
            Value = "";
            _Guid = Guid.NewGuid();
            Type = PropertyType.OBJECT;
        }
        public Property(String name, Object value)
        {
            Name = name;
            Value = value;
            _Guid = Guid.NewGuid();
            Type = PropertyType.OBJECT;
        }
        public Property(String name, Object value, PropertyType type)
        {
            Name = name;
            Value = value;
            _Guid = Guid.NewGuid();
            Type = type;
        }

        public String Name
        {
            get
            {
                return _Name;
            }
            set
            {
                _Name = value;
                NotifyPropertyChanged(x => x.Name);
            }
        }
        public Object Value
        {
            get
            {
                return _Value;
            }
            set
            {
                _Value = value;
                NotifyPropertyChanged(x => x.Value);
            }
        }
        public Guid Guid
        {
            get
            {
                return _Guid;
            }
        }
        public PropertyType Type
        {
            get
            {
                return _Type;
            }
            set
            {
                _Type = value;
                NotifyPropertyChanged(x => x.Type);
            }
        }

        #region INotifyPropertyChanged Member

        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged<TValue>(System.Linq.Expressions.Expression<Func<Property, TValue>> propertySelector)
        {
            if (PropertyChanged != null)
            {
                var memberExpression = propertySelector.Body as System.Linq.Expressions.MemberExpression;
                if (memberExpression != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs(memberExpression.Member.Name));
                }
            }
        }
        #endregion

    }
}